//
//  TodaySecondViewController.m
//  UI_A段项目_iDaily Watch
//
//  Created by 刘旭 on 14-10-14.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "TodaySecondViewController.h"
#import "TodayListSubViewController.h"
#import "AFHTTPRequestOperationManager.h"
#import "UIButton+WebCache.h"
#import "TodaySecond.h"
@interface TodaySecondViewController ()<UIScrollViewDelegate>
@property(nonatomic, retain)UIScrollView *scrollView;
@property(nonatomic, retain)UILabel *label1;
@property(nonatomic, retain)UILabel *label2;
@property(nonatomic, retain)UIButton *button;
@property(nonatomic, retain)NSMutableArray *dataArrOne;
@property(nonatomic, retain)UITableView *tableView;
@end

@implementation TodaySecondViewController
- (void)dealloc
{
    [_scrollView release];
    [_dataArrOne release];
    [super dealloc];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
      [self getData];
//        self.dataArrOne = [NSMutableArray array];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor blackColor];
    
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"TodaySecond.jpg"]];
    
      //[self scrollView1];
            //[self.view reloadInputViews];
    // Do any additional setup after loading the view.
}

- (void)getData
{
    self.dataArrOne = [NSMutableArray array];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:@"http://watch-cdn.idailywatch.com/api/list/cover/zh-hans?page=1&ver=iphone&app_ver=9" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        for (NSDictionary *dic in responseObject) {
            TodaySecond *sub = [[TodaySecond alloc]init];
            sub.cover_landscape = [dic objectForKey:@"cover_landscape"];
            sub.title = [dic objectForKey:@"title"];
            sub.source = [dic objectForKey:@"source"];
            [_dataArrOne addObject:sub];
//            [self.view reloadInputViews];
            
        }
        self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 100, 320, 270)];
        _scrollView.pagingEnabled = YES;
        _scrollView.bounces = NO;
        //        _scrollView.backgroundColor = [UIColor greenColor];
        _scrollView.contentSize = CGSizeMake(160 * 40, 270);
        //        [_scrollView setShowsHorizontalScrollIndicator:NO];
        _scrollView.delegate = self;
        [self.view addSubview:_scrollView];
        for (int i = 0; i < 40; i++) {
            self.button = [UIButton buttonWithType:UIButtonTypeCustom];
            _button.frame = CGRectMake(15 + 160 * i, 20, 150, 200);
            _button.backgroundColor = [UIColor cyanColor];
            _button.tag = i + 1000;
            [_button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
            [_scrollView addSubview:_button];
            
            [_button setBackgroundImageWithURL:[NSURL URLWithString:[_dataArrOne[i]cover_landscape]] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"t11.png"]];
            
            self.label1 = [[UILabel alloc]initWithFrame:CGRectMake(15 + 160 * i, 20 + 200, 150, 20)];
            _label1.font = [UIFont systemFontOfSize:12];
            _label1.backgroundColor = [UIColor colorWithWhite:0.1 alpha:0.4];
            _label1.textAlignment = NSTextAlignmentCenter;
            _label1.text = [_dataArrOne[i]title];
            [self.scrollView addSubview:_label1];
            
            self.label2 = [[UILabel alloc]initWithFrame:CGRectMake(15 + 160 * i, 20 + 200 + 20, 150, 20)];
            _label2.font = [UIFont systemFontOfSize:12];
            _label2.backgroundColor = [UIColor colorWithWhite:0.1 alpha:0.4];
            _label2.textAlignment = NSTextAlignmentLeft;
            _label2.text = [_dataArrOne[i]source];
            [self.scrollView addSubview:_label2];
        }

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
    
    
}
- (void)buttonAction:(UIButton *)sender
{
    TodayListSubViewController *vc = [[TodayListSubViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
    vc.count = sender.tag;
    
    [vc release];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
